package cn.bytets.rpc.api.message;

import cn.bytets.rpc.api.Channel;
import cn.bytets.rpc.api.exchange.DefaultFuture;
import cn.bytets.rpc.api.headler.ChannelHandler;

public class ChannelEventRunnable implements Runnable{

    private final ChannelHandler handler;

    private final Channel channel;

    private final ChannelState channelState;

    private final Object data;

    private final Throwable exception;

    public ChannelEventRunnable(ChannelHandler handler,
                                Channel channel,
                                ChannelState channelState,
                                Object response,
                                Throwable exception){
        this.handler = handler;
        this.channel = channel;
        this.channelState = channelState;
        this.data = response;
        this.exception = exception;
    }
    public ChannelEventRunnable(ChannelHandler handler,
                                Channel channel,
                                ChannelState channelState,
                                Throwable exception){
        this(handler,channel,channelState,null,exception);
    }

    public ChannelEventRunnable(ChannelHandler handler,
                                Channel channel,
                                ChannelState channelState,
                                Object response){
        this(handler,channel,channelState,response,null);
    }
    @Override
    public void run() {
        if (channelState == ChannelState.RECEIVED){
            DefaultFuture.received(channel,(Response)data,false);
        } else {
            System.out.println("ChannelEventRunnable状态"+channelState);
        }
    }
}
